import Vue from 'vue'
import VueRouter from 'vue-router'
// import Login from  '../components/login.vue'
const Login = () => import(/* webpackChunkName: "group-login" */ '../components/login.vue')
// import Home from '../components/home/home'
const Home = () => import(/* webpackChunkName: "group-Home" */ '../components/home/home')
// import Welcome from '../components/home/welcome'
const Welcome = () => import(/* webpackChunkName: "group-Welcome" */ '../components/home/welcome')
// import User from '../components/home/user/User'
const User = () => import(/* webpackChunkName: "group-User" */ '../components/home/user/User')
// import Rights from '../components/home/limits/Rights'
const Rights = () => import(/* webpackChunkName: "group-Limits" */ '../components/home/limits/Rights')
// import Roles from '../components/home/limits/Roles'
const Roles = () => import(/* webpackChunkName: "group-Limits" */ '../components/home/limits/Roles')
// import Sort from '../components/home/goods/Sort'
const Sort = () => import(/* webpackChunkName: "group-Goods" */ '../components/home/goods/Sort')
// import Params from '../components/home/goods/Params'
const Params = () => import(/* webpackChunkName: "group-Goods" */ '../components/home/goods/Params')
// import GoodList from '../components/home/goods/GoodsList'
const GoodList = () => import(/* webpackChunkName: "group-Goods" */ '../components/home/goods/GoodsList')
// import Add from '../components/home/goods/Add'
const Add = () => import(/* webpackChunkName: "group-Goods" */ '../components/home/goods/Add')
// import Order from '../components/home/order/Order'
const Order = () => import(/* webpackChunkName: "group-Order" */ '../components/home/order/Order')
// import Report from '../components/home/report/Report'
const Report = () => import(/* webpackChunkName: "group-Order" */ '../components/home/report/Report')

Vue.use(VueRouter)

  const routes = [
    {
      path:'/login',
      component:Login
    },
    {
      path:'',
      redirect:'/login'
    },
    {
      path:'/home',
      component:Home,
      redirect:'/welcome',
      children:[
        {
          path:'/welcome',
          component:Welcome
        },
        {
          path:'/users',
          component:User
        },
        {
          path:'/rights',
          component:Rights
        },
        {
          path:'/roles',
          component:Roles
        },
        {
          path:'/categories',
          component:Sort
        },
        {
          path:'/params',
          component:Params
        },
        {
          path:'/goods',
          component:GoodList
        },
        {
          path:'/goods/add',
          component:Add
        },
        {
          path:'/orders',
          component:Order
        },
        {
          path:'/reports',
          component:Report
        }
      ]
    }
  
]

const router = new VueRouter({
  routes
})
router.beforeEach((to,from,next) => {
  if (to.path === '/login') return next();
  const token = window.sessionStorage.getItem('token')
  if (!token) return next('/login')
  next()
})

export default router
